<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="../js/jquery-1.8.3.js"></script>
</head>
<body>
<form name="form">
    <input class="c1" type="text" name="test" value="-0.8"/>
    <input name="code" type="text" onkeyup="check(this)"/>
    <input type="textarea" cols="10" rows="10" style="vertical-align: top;outline:none;width: 100px;height: 100px;"/>
    <textarea name="aa" id="aa" cols="30" rows="10"></textarea>
</form>
<script>
    /*$(function(){
        $(".readval").each(function(){
            alert($(this).val());
            //var reg = /^\d*.\d{2}\d*!/;
            //var reg = /^(([1-9]{1}\\d*)\([0]{1})(\\.(\\d){0,2})?$/;
            var reg = /^(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d){0,2})?$/;
            alert($(this).val().match(reg));
            alert(reg.exec($(this).val()));
            console.log($(this).val().match(reg));
            $(this).val($(this).val().match(reg));
        });
    });*/
    window.onload=function(){
        var aa = document.getElementsByClassName("c1")[0];
        var bb = aa.value;
        //1.小数位数为0,时,添加两位为0的小数
        //小数位数为1位时,补一个0
        if(!/\./.test(bb)) {
            form.test.value=bb+".00";
        }else if(/(\.\d{1})$/.test(bb)){
            form.test.value=bb+"0";
        }else{
            var reg = /((^(\-?[1-9]{1})\d*|^(\-?0))\.)\d{2}/;
            form.test.value=bb.match(reg)[0];
        }
    }
    function check(obj){
        //var text = document.getElementsByName("code")[0];
        obj.value = obj.value.replace(/[^-?\d.]/g,"");
        obj.value = obj.value.replace(/\.{2,}/g,"");
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/g,"$1$2.$3");
    }


</script>
</body>
</html>